package cn.edu.hubu.javaparkinglot.controller;

import cn.edu.hubu.javaparkinglot.VO.ResultVO;
import cn.edu.hubu.javaparkinglot.entity.Seat;
import cn.edu.hubu.javaparkinglot.service.SeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class SeatController {
    @Autowired
    private SeatService seatService;

    // 根据车位编号查询车位信息的接口
    @RequestMapping("/seat/selectById")
    public ResultVO selectById(@RequestParam("seatId") int seatId) {
        // 调用SeatService中的selectBySeatId方法进行查询操作
        ResultVO vo = seatService.getSeatById(seatId);
        return vo;
    }

    // 添加车位信息的接口
    @RequestMapping("/seat/insert")
    public ResultVO insertSeat(Seat seat) {
        ResultVO vo = seatService.saveSeat(seat);
        return vo;
    }

    // 删除车位信息的接口
    @RequestMapping("/seat/delete")
    public ResultVO deleteSeat(@RequestParam("seatId") int seatId) {
        ResultVO vo = seatService.deleteSeat(seatId);
        return vo;
    }

    // 修改车位信息的接口
    @RequestMapping("/seat/modify")
    public ResultVO modifySeat(Seat seat) {
        ResultVO vo = seatService.updateSeat(seat);
        return vo;
    }
}